<?php
ini_set("display_errors", "1");
error_reporting(E_ALL | E_STRICT);
// $string =
// <<<'EOF'
// {"button":[{"name":"\u83dc\u5355\u4e00","sub_button":[{"type":"view","name":"\u767e\u5ea6","key":"baidu","url":"http://baidu.com"}]},{"name":"\u83dc\u5355\u4e8c","sub_button":[{"type":"view","name":"\u641c\u72d0","key":"sohu","url":"http://sohu.com"}]},{"name":"\u83dc\u5355\u4e09","sub_button":[{"type":"click","name":"\u5185\u90e8","key":"nei","url":""}]}]}
// EOF;
// $pattern = "#(\\\ue[0-9a-f]{3}|\\\ud83e|\\\udd14)#ie";
// $replace = '2';//"iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))";
// echo preg_replace($pattern, $replace, $string);
//
class demo {
    public $arr =array();
    public $brr = array(
        'button'=>array(
            array('type'=>'click','name'=>'今日头条'),
            array('type'=>'click','name'=>'今日头条'),
        )
    );
    public function arr_urlencode($arr){
        $new_arr = array();
        foreach($arr as $k=>&$v){
            $new_arr[urlencode($k)] = is_array($v)?self::arr_urlencode($v):urlencode($v);
		}
        return $new_arr;
    }
    public function js_encode($arr){
        $arr = $this->arr_urlencode($arr);
        var_dump($arr);
        $str = json_encode($arr);
        echo $str;
    }

}

$subject = new demo;
$subject->arr = array(
    'button'	=>	array(
        array(
            'name'=>'扫码',
            'sub_button'=>array(

                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
            )
        ),
        array(
            'name'=>'发图',
            'sub_button'=>array(

                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
            )
        ),
        array(
            'name'=>'点击',
            'sub_button'=>array(

                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
                array(
                    'type'=>'click',
                    'name'=>'今日头条',
                    'key'=>'v1001'
                ),
            )
        ),
    )
);
//var_dump($subject->arr);
$subject->js_encode($subject->arr);
echo json_encode($subject->arr);
var_dump('a');